package com.ziytek.web.citizen.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @className VirtualThreadUtil
 * @description: 虚拟线程工具类
 * @jdkVersion: 1.8
 * @author: fhx
 * @date: 2024/7/2 9:53
 */
public class VirtualThreadUtil {
    /**
     * 创建虚拟线程
     */
   // private static final ExecutorService EXECUTOR = Executors.newVirtualThreadPerTaskExecutor();
    /**
     * 创建线程池，线程数为CPU核数
     */
    private static final ExecutorService EXECUTOR = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());

    public static ExecutorService getExecutor() {
        return EXECUTOR;
    }

    public static void execute(Runnable runnable) {
        EXECUTOR.execute(runnable);
    }

    public static void shutdown() {
        EXECUTOR.shutdown();
    }

}
